<div class="table-responsive">
    <table class="table table-bordered table-hover">
        <thead>
        <tr>
            <td style="width: 1px;" class="text-center">
                <input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);">
            </td>
            <td class="text-center">
                发送人
            </td>
            <td class="text-center">
                标题
            </td>
            <td class="text-center">
                类型
            </td>
            <td class="text-center">
                状态
            </td>
            <td class="text-center">
                发送时间
            </td>
            <td class="text-center">操作</td>
        </tr>
        </thead>
        <tbody>
		  <?php if(empty($data)) {?>  
	                       <tr><td style="text-align: center;" colspan="7">查询不到相关数据</td></tr>
	                 <?php }?>  
        <volist name="data" id="list">
            <tr>
                <td class="text-center">
                    <input type="checkbox" name="selected[]" value="{$list.message_id}" gs="{$list.type}">
                </td>
                <td class="text-center">{$list.name}</td>
                <td class="text-center">{$list.title}</td>
                <td class="text-center">
                    <if condition="$list['type'] eq 0">
          						临时聊天
          					<elseif condition="$list['type'] eq 1"/>
          						系统消息
          					</if>
                </td>
                <td class="text-center" id="status">
                   	<if condition="$list['status'] eq 0">
          						  <span class="text-danger"><i class="icon-circle"></i>未读</span>
          					<elseif condition="$list['status'] eq 1"/>
          						  <span class="text-primary"><i class="icon-ok"></i>已读</span>
          				  </if>
                </td>
                <td class="text-center">{$list.send_time|date='Y-m-d H:i',###}</td>
                <td class="text-center">
                  <a onclick="return check(this)" data-type="{$list.type}" href="{:U('Msg/detail',array('id'=>$list['message_id'],'replyid'=>$list['replyid'],'sender'=>$list['sender'],'type'=>$list['type']))}" " data-id="{$list.message_id}"  data-toggle="tooltip" title="" class="btn btn-primary btn-xs" data-original-title="编辑"><i class="icon-search"></i>查看</a>
               		<a class="btn btn-danger btn-xs" href="javascript:void(0)" data-type="{$list.type}" data-url="{:U('Msg/del')}" data-id="{$list.message_id}" onclick="de(this)"><i class="icon-trash"></i>删除</a>
                </td>
            </tr>
        </volist>
        </tbody>
    </table>
    <div class="navbar navbar-default">
        <div class="navbar-form form-inline pull-left">
            <select name="operate" id="operate" class="form-control selectDemo2">
                <option value="0">多选操作</option>
                <option value="hide">标记为已读</option>
                <option value="del">删除</option>
            </select>
            <button class="btn btn-primary" onclick="op()">执行</button>
        </div>
        <div class="navbar-form form-inline pull-right">
        	  <button class="btn btn-submit" data-toggle="modal" href="#sendMessageBox"><i class="glyphicon glyphicon-envelope"></i>发送站内信</button>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-xs-12 text-center">{$page}</div>
</div>


<script>
    $(".pagination  a").click(function(){
        var page = $(this).data('p');
        ajax_get_table('search-form2',page);
    });

    //sendMessageForm
    function sendMessageForm(){
        var user = $('#user option:selected').val();
        var text = $('#text').val();
        var title = $('#title').val();
        var error = '';
         if(user == '请选择'){
            error += '收信人不能为空 <br/>';
        }
        if(title == ''){
            error += '标题不能为空 <br/>';
        }
        if(text == ''){
            error += '站内信内容不能为空 <br/>';
        }
        if(error){
      		layer.alert(error, {icon: 2});
            return false;
        } 
	   	 $.ajax({
	   		type : 'post',
	   		url : '/Msg/doSendMessage',
	   		data : {user:user,text:text,title:title},
	   		dataType : 'json',
	   		success : function(res){
	   			 if(!res.errNo){
	   				 layer.msg(res.msg,{time:2000});
	   				 $('#sendMessageBox').modal('hide');
	  	          }else{
	  	        	 layer.msg(res.msg,{time:2000});
	  	          }
	   		}
	    })
    }
    
    function op(){
        //获取操作
      var op_type = $('#operate').find('option:selected').val();
      if(op_type == 0){
    			layer.msg('请选择操作', {icon: 1,time: 1000});   //alert('请选择操作');
                return;
        }
        //获取选择的id
        var select = $('input[name*="selected"]:checked');
        //获取选择的个体消息数量
        //var selected = $('input[name*="selected"][gs=0]:checked');
        //获取选择的系统消息数量
       // var selecteder = $('input[name*="selected"][gs=1]:checked');
        var selected_id = [];
        if(select.length < 1){
			layer.msg('请选择消息', {icon: 1,time: 1000}); //            alert('请选择项目');
            return;
        }
        $(select).each(function(){
            selected_id.push($(this).val());
        })
        //获取个体值
        var len = select.length;
        var a = $("#msg",window.parent.document).text();
			var b = a - len;
			if(b<=0){
				b = '';
			}
	     //获取系统值
		/* var leng = selecteder.length;
        var aa = $("#allmsg",window.parent.document).text();
			var bb = aa - leng;
			if(bb<=0){
				bb = '';
			} */
		var c = b;
     	 $.ajax({
      		type : 'post',
      		url : '/Msg/op',
      		data : {selected:selected_id,type:op_type},
      		dataType : 'json',
      		success : function(res){
      			 if(!res.errNo){
      				 layer.msg(res.msg,{time:2000});
      				$("#msg",window.parent.document).text(b);
      				//$("#allmsg",window.parent.document).text(bb);
      				$("#he",window.parent.document).text(c);
      				if(len>0){
      					$("#drop",window.parent.document).load("/Index/ajaxmes #drop li");
      					setTimeout("location.reload()",2000);
      				}
      				/* if(leng>0){
      					$("#noti",window.parent.document).load("/Index/index #noti li");
      				} */
      				//setTimeout("location.reload()",2000);
     	          }else{
     	        	 layer.msg(res.msg,{time:2000});
     	          }
      		}
         })
          
    }
    
    //单个删除
    function de(obj){
    	layer.confirm('确认删除？', {
  		  btn: ['确定','取消'] //按钮
  		}, function(){
  			//var type = $(obj).attr('data-type');
  			var c = $("#he",window.parent.document).text() - 1;
  			//if(type==0){
  			  var b = $("#msg",window.parent.document).text() - 1;
  			  if(b<=0){
  				  b="";
  			  }
  			if(c<=0){
				  c="";
			  }
  			//}
  	/* 		if(type==1){
    			  var bb = $("#allmsg",window.parent.document).text() - 1;
    			  if(bb<=0){
    				  bb="";
    			  }
    			} */
 				$.ajax({
 					type : 'post',
 					url : $(obj).attr('data-url'),
 					data : {del_id:$(obj).attr('data-id')},
 					dataType : 'json',
 					success : function(data){
 						if(!data.errNo){
 		      				 layer.msg(data.msg,{time:2000});
 		      				$("#msg",window.parent.document).text(b);
 		      				$("#allmsg",window.parent.document).text(bb);
 		      				$("#he",window.parent.document).text(c);
 		      				if(type==0){
 		      					$("#drop",window.parent.document).load("/Index/ajaxmes #drop li");
 		      				}else{
 		      					$("#noti",window.parent.document).load("/Index/ajaxmes #noti li");
 		      				}
 		      				 setTimeout("location.reload()",2000);
 		     	        }else{
 		     	        	 layer.msg(data.msg,{time:2000});
 		     	        }
 					}
 				})
  		}, function(){
  			// 取消
  		});
  			return false;
  		}
    
    //查看详情操作
    function check(o){
    	var a = $(o).attr('data-type');
		//if(a==0){
			var b = $("#msg",window.parent.document).text() - 1;
			  if(b<=0){
				  b="";
			  }
			  $("#msg",window.parent.document).text(b);
		// }
	/* 	if(a==1){
			var bb = $("#allmsg",window.parent.document).text() - 1;
			  if(bb<=0){
				  bb="";
			  }
			  $("#almsg",window.parent.document).text(bb);
		 } */
		var c = $("#he",window.parent.document).text() - 1;
		if(c<0){
			c="";
		}
		$("#he",window.parent.document).text(c);
    }
    
    // //发送站内信
    // function send_message(id)
    // {
    //     var url = "{:U('/Msg/sendMessage')}";
    //     layer.open({
    //         type: 2,
    //         title: '站内信',
    //         shadeClose: true,
    //         shade: 0.8,
    //         area: ['580px', '500px'],
    //         offset: ['100px', '50px'],
    //         content: url
    //     });
    // }
    /**
     * 回调函数
     */
     function call_back(v) {
        layer.closeAll();
        if (v == 1) {
            layer.msg("发送成功");
        } else {
            layer.msg('发送失败');
        }
     } 
</script>